package com.uqbar.game.asteroid.tipe;

import java.awt.Color;
import com.uqbar.game.AsteroidComponent;
import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Animation;
import com.uqbar.vainilla.appearances.Sprite;

public abstract class Asteroid extends AsteroidComponent {

	private double movX, movY;
	private int speed;
	private Color color = Color.BLUE;
	protected Sprite[] asteroidSprites = new Sprite[32];
	protected Animation asteroidAnimation;
	
	public Asteroid(int x, int y, int speed, double dirX, double dirY) {
		super(x, y);
		this.movX = dirX;
		this.movY = dirY;
		this.speed = speed;
	}
	
	public void update(DeltaState deltaState) {
		super.update(deltaState);
		this.alignWithDiameter();
		this.moveAsteroid(deltaState);
	}

	protected abstract void alignWithDiameter(); 

	private void moveAsteroid(DeltaState deltaState) {
		double movX = this.movX * deltaState.getDelta() * this.speed;
		double movY = this.movY * deltaState.getDelta() * this.speed;
		
		this.move(movX, movY);	
	}
	
	
	protected void initializeAnimations(double diameter){
		for(int i= 0; i<32; i++){
			Sprite s = Sprite.fromImage("/asteroids/asteroids"+i+".png");
			this.asteroidSprites[i]= s.scale(diameter/s.getHeight(),diameter/s.getWidth());
		}
		this.asteroidAnimation = new Animation(0.05, this.asteroidSprites);
		
	}
	
	public Sprite[] getAsteroidSprites() {
		return asteroidSprites;
	}

	public void setAsteroidSprites(Sprite[] asteroidSprites) {
		this.asteroidSprites = asteroidSprites;
	}

	public Animation getAsteroidAnimation() {
		return asteroidAnimation;
	}

	public void setAsteroidAnimation(Animation asteroidAnimation) {
		this.asteroidAnimation = asteroidAnimation;
	}

	public double getMovX() {
		return movX;
	}
	
	public void setMovX(double movX) {
		this.movX = movX;
	}
	
	public double getMovY() {
		return movY;
	}
	
	public void setMovY(double movY) {
		this.movY = movY;
	}
	
	public int getSpeed() {
		return speed;
	}
	
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	
	public Color getColor() {
		return color;
	}
	
	public void setColor(Color color) {
		this.color = color;
	}

	public abstract void exploit();

	public abstract int getDiameter();

	public abstract int getScore(); 
	
}
